package com.maiyuren.dict_page_view_plugin;
import com.maiyuren.dict_page_view_plugin.dictpageview.*;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import io.flutter.Log;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugin.platform.PlatformViewFactory;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

/// 原生的组件

/// 一个继承PlatformView类 返回具体的原生组件
class DictPagePlatformView implements PlatformView {
    Context context;
    Integer _id = 0;

    public DictPageView view = null;

    public static Map<Integer, DictPagePlatformView> s_views = new HashMap<Integer, DictPagePlatformView>();

    DictPagePlatformView(Context context, int viewId) {
        this.context = context;
        this._id = viewId;
        view = new DictPageView(context, _id);
        s_views.put(_id, this);
    }

    /// 这里返回原生组件
    @Nullable
    @Override
    public View getView() {
        return view;
    }

    @Override
    public void dispose() {
        s_views.put(_id, null);
    }
}

/// 新建一个工厂类 返回 PlatformView 类实例
class DictPagePlatformViewFactory extends PlatformViewFactory {

    /// 与flutter中 creationParams creationParamsCodec 对应 不实现此方法args则为null
    public DictPagePlatformViewFactory() {
        super(StandardMessageCodec.INSTANCE);
    }

    @NonNull
    @Override
    public PlatformView create(Context context, int viewId, @Nullable Object args) {
        //args 根据这个参数可以返回不同的view
        return new DictPagePlatformView(context, viewId);
    }
}